//package com.toycloud.config.controller;
//
//import java.io.IOException;
//import java.util.List;
//import java.util.Set;
//import java.util.stream.Collectors;
//import javax.servlet.http.HttpServletResponse;
//
//import com.toycloud.security.annotation.InnerAuth;
//import com.toycloud.security.annotation.RequiresPermissions;
//import com.toycloud.security.utils.SecurityUtils;
//import com.toycloud.system.domain.SysRole;
////import com.toycloud.system.service.SysConfigService;
//import com.toycloud.system.service.SysPermissionService;
//import com.toycloud.system.service.SysRoleService;
//import com.toycloud.system.service.SysUserService;
//import org.apache.commons.lang3.ArrayUtils;
//import com.toycloud.common.core.web.controller.BaseController;
//import com.toycloud.common.core.web.domain.AjaxResult;
//import com.toycloud.common.core.web.page.TableDataInfo;
//import com.toycloud.system.domain.SysUser;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.validation.annotation.Validated;
//import org.springframework.web.bind.annotation.DeleteMapping;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PathVariable;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.PutMapping;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.multipart.MultipartFile;
//import com.toycloud.common.core.domain.R;
//import com.toycloud.common.core.utils.StringUtils;
//import com.toycloud.common.core.utils.poi.ExcelUtil;
//import com.toycloud.system.log.annotation.Log;
//import com.toycloud.system.log.enums.BusinessType;
//
//import com.toycloud.system.model.LoginUser;
//
///**
// * 用户信息
// *
// * @author ruoyi
// */
//@RestController
//@RequestMapping("/system/user")
//public class SysUserController extends BaseController
//{
//    @Autowired
//    private SysUserService sysUserService;
//
//    @Autowired
//    private SysRoleService sysRoleService;
//
//    @Autowired
//    private SysPermissionService sysPermissionService;
//
//    /**
//     * 获取当前用户信息
//     */
//    @InnerAuth
//    @GetMapping("/info/{username}")
//    public R<LoginUser> info(@PathVariable("username") String username)
//    {
//        SysUser sysUser = sysUserService.selectUserByUserName(username);
//        if (StringUtils.isNull(sysUser))
//        {
//            return R.fail("用户名或密码错误");
//        }
//        // 角色集合
//        Set<String> roles = sysPermissionService.getRolePermission(sysUser);
//        // 权限集合
//        Set<String> permissions = sysPermissionService.getMenuPermission(sysUser);
//        LoginUser sysUserVo = new LoginUser();
//        sysUserVo.setSysUser(sysUser);
//        sysUserVo.setRoles(roles);
//        sysUserVo.setPermissions(permissions);
//        return R.ok(sysUserVo);
//    }
//
//    /**
//     * 获取用户信息
//     *
//     * @return 用户信息
//     */
//    @GetMapping("getInfo")
//    public AjaxResult getInfo()
//    {
////        SysUser user = sysUserService.selectUserById(SecurityUtils.getUserId());
//        SysUser user = sysUserService.selectUserById(1L);
//        // 角色集合
//        Set<String> roles = sysPermissionService.getRolePermission(user);
//        // 权限集合
//        Set<String> permissions = sysPermissionService.getMenuPermission(user);
//        AjaxResult ajax = AjaxResult.success();
//        ajax.put("user", user);
//        ajax.put("roles", roles);
//        ajax.put("permissions", permissions);
//        return ajax;
//    }
//
////    /**
////     * 根据用户编号获取详细信息
////     */
////    @RequiresPermissions("system:user:query")
////    @GetMapping(value = { "/", "/{userId}" })
////    public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId)
////    {
////        sysUserService.checkUserDataScope(userId);
////        AjaxResult ajax = AjaxResult.success();
////        List<SysRole> roles = sysRoleService.selectRoleAll();
////        ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
////        if (StringUtils.isNotNull(userId))
////        {
////            SysUser sysUser = sysUserService.selectUserById(userId);
////            ajax.put(AjaxResult.DATA_TAG, sysUser);
////            ajax.put("roleIds", sysUser.getRoles().stream().map(SysRole::getRoleId).collect(Collectors.toList()));
////        }
////        return ajax;
////    }
////
////    /**
////     * 新增用户
////     */
////    @RequiresPermissions("system:user:add")
////    @Log(title = "用户管理", businessType = BusinessType.INSERT)
////    @PostMapping
////    public AjaxResult add(@Validated @RequestBody SysUser user)
////    {
////        if (!sysUserService.checkUserNameUnique(user))
////        {
////            return error("新增用户'" + user.getUserName() + "'失败，登录账号已存在");
////        }
////        else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !sysUserService.checkPhoneUnique(user))
////        {
////            return error("新增用户'" + user.getUserName() + "'失败，手机号码已存在");
////        }
////        else if (StringUtils.isNotEmpty(user.getEmail()) && !sysUserService.checkEmailUnique(user))
////        {
////            return error("新增用户'" + user.getUserName() + "'失败，邮箱账号已存在");
////        }
////        user.setCreateBy(SecurityUtils.getUsername());
////        user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
////        return toAjax(sysUserService.insertUser(user));
////    }
////
////    /**
////     * 修改用户
////     */
////    @RequiresPermissions("system:user:edit")
////    @Log(title = "用户管理", businessType = BusinessType.UPDATE)
////    @PutMapping
////    public AjaxResult edit(@Validated @RequestBody SysUser user)
////    {
////        sysUserService.checkUserAllowed(user);
////        sysUserService.checkUserDataScope(user.getUserId());
////        if (!sysUserService.checkUserNameUnique(user))
////        {
////            return error("修改用户'" + user.getUserName() + "'失败，登录账号已存在");
////        }
////        else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !sysUserService.checkPhoneUnique(user))
////        {
////            return error("修改用户'" + user.getUserName() + "'失败，手机号码已存在");
////        }
////        else if (StringUtils.isNotEmpty(user.getEmail()) && !sysUserService.checkEmailUnique(user))
////        {
////            return error("修改用户'" + user.getUserName() + "'失败，邮箱账号已存在");
////        }
////        user.setUpdateBy(SecurityUtils.getUsername());
////        return toAjax(sysUserService.updateUser(user));
////    }
////
////    /**
////     * 删除用户
////     */
////    @RequiresPermissions("system:user:remove")
////    @Log(title = "用户管理", businessType = BusinessType.DELETE)
////    @DeleteMapping("/{userIds}")
////    public AjaxResult remove(@PathVariable Long[] userIds)
////    {
////        if (ArrayUtils.contains(userIds, SecurityUtils.getUserId()))
////        {
////            return error("当前用户不能删除");
////        }
////        return toAjax(sysUserService.deleteUserByIds(userIds));
////    }
////
////    /**
////     * 重置密码
////     */
////    @RequiresPermissions("system:user:edit")
////    @Log(title = "用户管理", businessType = BusinessType.UPDATE)
////    @PutMapping("/resetPwd")
////    public AjaxResult resetPwd(@RequestBody SysUser user)
////    {
////        sysUserService.checkUserAllowed(user);
////        sysUserService.checkUserDataScope(user.getUserId());
////        user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
////        user.setUpdateBy(SecurityUtils.getUsername());
////        return toAjax(sysUserService.resetPwd(user));
////    }
////
////    /**
////     * 状态修改
////     */
////    @RequiresPermissions("system:user:edit")
////    @Log(title = "用户管理", businessType = BusinessType.UPDATE)
////    @PutMapping("/changeStatus")
////    public AjaxResult changeStatus(@RequestBody SysUser user)
////    {
////        sysUserService.checkUserAllowed(user);
////        sysUserService.checkUserDataScope(user.getUserId());
////        user.setUpdateBy(SecurityUtils.getUsername());
////        return toAjax(sysUserService.updateUserStatus(user));
////    }
////
////    /**
////     * 根据用户编号获取授权角色
////     */
////    @RequiresPermissions("system:user:query")
////    @GetMapping("/authRole/{userId}")
////    public AjaxResult authRole(@PathVariable("userId") Long userId)
////    {
////        AjaxResult ajax = AjaxResult.success();
////        SysUser user = sysUserService.selectUserById(userId);
////        List<SysRole> roles = sysRoleService.selectRolesByUserId(userId);
////        ajax.put("user", user);
////        ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
////        return ajax;
////    }
////
////    /**
////     * 用户授权角色
////     */
////    @RequiresPermissions("system:user:edit")
////    @Log(title = "用户管理", businessType = BusinessType.GRANT)
////    @PutMapping("/authRole")
////    public AjaxResult insertAuthRole(Long userId, Long[] roleIds)
////    {
////        sysUserService.checkUserDataScope(userId);
////        sysUserService.insertUserAuth(userId, roleIds);
////        return success();
////    }
//}
